package com.example.demo.study.exception;

import java.util.Scanner;

// exception 异常处理

public class Person2 {
    private String nanme;
    private int age;
    private String sex;

    public String getNanme() {
        return nanme;
    }

    public void setNanme(String nanme) {
        this.nanme = nanme;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws NumberFormatException {
        if(age < 0 || age >= 100){
            throw new NumberFormatException("年龄不合法");
        }else {
            this.age = age;
        }

    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) throws IllegalArgumentException{
        // 判断性别是否合法  只有 男，女
        if(sex.equals("男") || sex.equals("女")){
            this.sex = sex;
        }else{
            throw new IllegalArgumentException("性别输入错误");
        }

    }
}
